package com.bing.java.collection.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

/**
 * Map得4种遍历方式
 * @author bing
 *
 * 2019年11月9日 下午4:59:17
 */
public class MapIterator {
	public static void main(String[] args) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("熊大", "棕色");
		map.put("熊二", "黄色");

		/**
		 * entrySet
		 */
		for (Map.Entry<String, String> entry : map.entrySet()) {
			String mapKey = entry.getKey();
			String mapValue = entry.getValue();
			System.out.println(mapKey + ":" + mapValue);
		}
		
		
		/**
		 * keySet
		 */
		for(String key : map.keySet()){
		    System.out.println(key+":"+map.get(key));
		}
		//value
//		for(String value : map.values()){
//		    System.out.println(value);
//		}
		
		/**
		 * Iterator
		 */
		Iterator<Entry<String, String>> entries = map.entrySet().iterator();
		while(entries.hasNext()){
		    Entry<String, String> entry = entries.next();
		    String key = entry.getKey();
		    String value = entry.getValue();
		    System.out.println(key+":"+value);
		}
		
		/**
		 * java8  Lambda
		 */
		 map.forEach((k, v) -> {System.out.println("key:value = " + k + ":" + v);});
	}
}
